package bomb.logic.levels;

import java.util.logging.Logger;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import bomb.Game;
import bomb.logic.Bomba;
import bomb.logic.Level;
import bomb.logic.Lugar;
import bomb.logic.Personagem;
import bomb.utils.CompleteTest;
import bomb.utils.Highscores;
import bomb.utils.Letras;

public class Level4 extends Level {
    public Level4(int id){
        super(id,8);
    }
    @Override
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        super.init(gc, sbg);
        /*********************** LOCAL DAS BOMBAS?? **************************/
        hero = new Personagem(200, 40);
        
        bombs[0] = new Bomba(200, 80, false);
        bombs[1] = new Bomba(200, 120, false);
        bombs[2] = new Bomba(160, 160, false);
        bombs[3] = new Bomba(240, 160, false);
        bombs[4] = new Bomba(200, 200, false);
        bombs[5] = new Bomba(160, 240, false);
        bombs[6] = new Bomba(240, 240, false);
        bombs[7] = new Bomba(200, 280, false);


        places[0] = new Lugar(160, 120, false);
        places[1] = new Lugar(160, 200, false);
        places[2] = new Lugar(160, 280, false);
        places[3] = new Lugar(200, 160, false);
        places[4] = new Lugar(200, 240, false);
        places[5] = new Lugar(240, 120, false);
        places[6] = new Lugar(240, 200, false);
        places[7] = new Lugar(240, 280, false);
        /*********************************************************************/
    }
    @SuppressWarnings("deprecation")
    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        super.render(gc, sbg, g);
        if(terminado){
            Game.getParabens().draw(100, 100);
            Letras.getLetra2().drawString(230, 210, ""+Integer.toString(hero.getMovs()), Color.black);
            Letras.getLetra1().drawString(240, 240, "moves", Color.black);
        }
    }
    
    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException {
        
        timer += 0.001;
        if (CompleteTest.test(places, numero)){
            if(timer>2.001){timer=0;}
            if (timer==0){
                terminado = true;
                for(int k=0;k<numero;k++){
            		bombs[k].setImg(2);
            	}
                Game.completeSound();
            }else{
                try {
                    Thread.sleep(2500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Level2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                }
                Highscores.setScore(this.ident, hero.getMovs());
                terminado = false;
                gc.reinit();
                sbg.enterState(Game.LEVELSELECTSTATE);
                
            }
        }
        super.update(gc, sbg, i);
        
    }
}
